/**
*长度不可变的单选框，是比较有用的东西，一定要固化，因为以后要用
*自己的监听器
*OnChoiceGroupChanged
*/
package kgame5.kgui.kcomp {
import kgame5.kutil.*;

import flash.display.*;
import flash.events.*;

public class SmartChoiceGroup extends EventDispatcher{
	public static const STR_EVENTTYPE:String="OnChoiceGroupChanged";
	//_______________Property__________________
	/**
	由mc_1,mc_2,mc_3..组成，frame1是没选中，frame2是选中
	*/
	private var mc_model:MovieClip;
	
	private var MAXNUM:int;
	//_______________Method______________
	public function SmartChoiceGroup(p_mc:MovieClip,count:int){
		
		mc_model=p_mc;
		
		MAXNUM=count;
		
		var i:int;
		for(i=0;i<MAXNUM;i++){
			var mc:MovieClip=mc_model["mc_"+i];
			
			mc.gotoAndStop(1);
			
			mc.idx=i;
			
			//mc.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler,false,0,true);
			Util.OnPress(mc, mouseDownHandler);
		}
		
	}
	public function getDO():DisplayObject{
		return mc_model;
	}
	private function mouseDownHandler(e:MouseEvent){
		var mc:MovieClip=e.currentTarget as MovieClip;
		//T.p("mouseDownHandler:"+mc.currentFrame);
		
		switch(mc.currentFrame){//选中
			case 1://没选中
				this.setSelIdx(mc.idx);
			break;
			case 2://选中
				//选中的点击则不动
			break;
		}
	}
	
	//返回选中的索引
	public function getSelIdx():int{
		for(var i:int=0;i<MAXNUM;i++){
			if(mc_model["mc_"+i].currentFrame==2){
				//T.p("getSelIdx"+i);
				return i;
			}
		}
		return -1;
	}
	//设置某个被选中
	public function setSelIdx(idx:int){
		//T.p("setSelIdx:"+idx);
		//都去没选中
		for(var j:int=0;j<MAXNUM;j++){
			mc_model["mc_"+j].gotoAndStop(1);
		}
		//自己选中
		mc_model["mc_"+idx].gotoAndStop(2);
		
		//通知自己的监听器说自己改了选择
		this.dispatchEvent(new Event(STR_EVENTTYPE));
	}	
	//
}//end of class
}